package cn.faster.project.controller;

import java.util.Arrays;

import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.util.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.faster.project.service.TeacherCardService;
import cn.faster.project.entity.TeacherCard;
import cn.faster.common.enums.CodeEnum;
import cn.faster.common.result.ResultBean;

import javax.validation.Valid;

/**
 * teacher_card控制器
 *
 * @author ViolentKangaroo
 * @email 1343643063@qq.com
 * @date 2021-09-01 16:19:43
 */
@RestController
@CrossOrigin
@AllArgsConstructor
@Api(value = "老师打卡记录" , tags = "老师打卡记录")
@RequestMapping("project/teachercard")
public class TeacherCardController {
    private final  TeacherCardService teacherCardService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取teacher_cardEntity分页数据" , notes = "获取teacher_card分页数据")
    //@RequiresPermissions("project:teachercard:list")
    public ResultBean<?> list(Page<TeacherCard> pages) {
        if (StringUtils.isEmpty(pages)) {
            return ResultBean.VALIDATE(CodeEnum.REQUIRED_PARAMETERS_ARE_EMPTY);
        }
        return ResultBean.SUCCESS(teacherCardService.findByPage(pages));
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "根据id，获取teacher_card" , notes = "根据id，获取teacher_card")
    //@RequiresPermissions("project:teachercard:info")
    public ResultBean<?> info(@PathVariable("id") Integer id) {
        if (StringUtils.isEmpty(id)) {
            return ResultBean.VALIDATE(CodeEnum.REQUIRED_PARAMETERS_ARE_EMPTY);
        }
        return ResultBean.SUCCESS(teacherCardService.getById(id));
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存teacher_card信息" , notes = "保存teacher_card信息")
    //@RequiresPermissions("project:teachercard:save")
    public ResultBean<?> save(@RequestBody @Valid TeacherCard teacherCard) {
        if (StringUtils.isEmpty(teacherCard)) {
            return ResultBean.VALIDATE(CodeEnum.REQUIRED_PARAMETERS_ARE_EMPTY);
        }
        return ResultBean.SUCCESS(teacherCardService.save(teacherCard));
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改teacher_card信息" , notes = "修改teacher_card信息")
    //@RequiresPermissions("project:teachercard:update")
    public ResultBean<?> update(@RequestBody @Valid TeacherCard teacherCard) {
        if(StringUtils.isEmpty(teacherCard)) {
            return ResultBean.VALIDATE(CodeEnum.REQUIRED_PARAMETERS_ARE_EMPTY);
        }
        return ResultBean.SUCCESS(teacherCardService.updateById(teacherCard));
    }

    /**
     * 删除
     */
    @DeleteMapping("delete/{id}")
    //@RequiresPermissions("project:teachercard:delete")
    public ResultBean<?> delete(@PathVariable("id") Integer id) {
        return ResultBean.SUCCESS(teacherCardService.removeById(id));
    }

}
